package com.imooc.miaosha.service;

import com.imooc.miaosha.domain.OrderInfo;
import com.imooc.miaosha.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class MiaoshaService {

	@Autowired
	GoodsService goodsService;

	@Autowired
	OrderService orderService;

	@Transactional
	public OrderInfo miaosha(Long userId, GoodsVo goods) {
		//减库存 下订单 写入秒杀订单
		int record = goodsService.reduceStock(goods);
		//order_info maiosha_order
		if(record>0){
			return orderService.createOrder(userId, goods);
		}
		return null;

	}

}
